home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume4 / xrobots / part01 next >
Encoding:
Text File  |  1989-06-04  |  65.7 KB  |  2,504 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i017:  xrobots, Part01/01
  5. Message-ID: <789@island.uu.net>
  6. Date: 4 Jun 89 21:43:49 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 2493
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Brian Warkentine <bwarkent@polyslo.CalPoly.EDU>
  12. Posting-number: Volume 4, Issue 17
  13. Archive-name: xrobots/part01
  14.  
  15. [ This is an X version of the classic game of robots.  For those not familiar
  16.   with robots, the idea is that you are chased by robots and the object is to
  17.   make them crash into each other before they get you.  This is a very nice
  18.   implementation of this game -- incredibly fun.  --argv ]
  19.  
  20. #! /bin/sh
  21. # This is a shell archive, meaning:
  22. # 1. Remove everything above the #! /bin/sh line.
  23. # 2. Save the resulting text in a file.
  24. # 3. Execute the file with /bin/sh (not csh) to create the files:
  25. #    Imakefile
  26. #    Makefile.nonImake
  27. #    README
  28. #    bitmaps.h
  29. #    callbacks.c
  30. #    callbacks.h
  31. #    game.c
  32. #    game.h
  33. #    graphics.c
  34. #    graphics.h
  35. #    help.c
  36. #    help.h
  37. #    main.c
  38. #    score.c
  39. #    score.h
  40. #    xrobots.man
  41. # This archive created: Tue May 30 14:19:53 1989
  42. export PATH; PATH=/bin:$PATH
  43. echo shar: extracting "'Imakefile'" '(642 characters)'
  44. if test -f 'Imakefile'
  45. then
  46.     echo shar: will not over-write existing file "'Imakefile'"
  47. else
  48. cat << \SHAR_EOF > 'Imakefile'
  49.  
  50.      SCORE_FILE = -DSCORE_FILE=\"/usr/games/lib/xrobots_scores\"
  51.       MAXSCORES = -DMAXSCORES=20
  52.            MAXX = -DMAXX=35
  53.            MAXY = -DMAXY=20
  54.         DEFINES = $(SCORE_FILE) $(MAXSCORES) $(MAXX) $(MAXY)
  55.  
  56.            SRCS = callbacks.c game.c graphics.c main.c score.c help.c
  57.            OBJS = callbacks.o game.o graphics.o main.o score.o help.o
  58.  
  59.        INCLUDES = -I$(TOP) -I$(TOOLKITSRC)
  60. LOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) -lm
  61.  
  62.  
  63. all:: xrobots
  64.  
  65. ComplexProgramTarget(xrobots)
  66. /*
  67.  *  The following is a matter of preference:
  68.  *
  69.  *  InstallManPage(xrobots,$(MANDIR))
  70.  *  InstallProgram(xrobots,$(BINDIR))
  71.  */
  72.  
  73. SHAR_EOF
  74. if test 642 -ne "`wc -c < 'Imakefile'`"
  75. then
  76.     echo shar: error transmitting "'Imakefile'" '(should have been 642 characters)'
  77. fi
  78. fi # end of overwriting check
  79. echo shar: extracting "'Makefile.nonImake'" '(1092 characters)'
  80. if test -f 'Makefile.nonImake'
  81. then
  82.     echo shar: will not over-write existing file "'Makefile.nonImake'"
  83. else
  84. cat << \SHAR_EOF > 'Makefile.nonImake'
  85.  
  86. #  For those of us who are still confused by Imake,
  87. #  this makefile is not its offspring.  :-)
  88.  
  89.  
  90.         TASK        = xrobots
  91. #       TASK        = /usr/games/xrobots
  92.  
  93.         SCORE_FILE    = -DSCORE_FILE=\"/usr/games/lib/xrobots_scores\"
  94.         MAXSCORES    = -DMAXSCORES=20
  95.         MAXX        = -DMAXX=35
  96.         MAXY        = -DMAXY=20
  97.  
  98.         DEFINES        = $(SCORE_FILE) $(MAXSCORES) $(MAXX) $(MAXY)
  99.  
  100.         INCDIR        = /usr/local/include
  101.         LIBDIR        = /usr/local/lib
  102.         LIBS        = -lXaw -lXt -lXmu -lX11 -lm
  103.  
  104.         DBXFLAGS    = 
  105.         CFLAGS        = $(DBXFLAGS) -I$(INCDIR) $(DEFINES)
  106.         LDFLAGS        = $(DBXFLAGS) -L$(LIBDIR) $(LIBS)
  107.  
  108.         CFILES        = main.c game.c callbacks.c graphics.c score.c help.c
  109.         OBJECTS        = main.o game.o callbacks.o graphics.o score.o help.o
  110.         INCLUDES    = game.h graphics.h bitmaps.h score.h help.h
  111.  
  112. default: $(TASK) 
  113.  
  114. $(TASK): $(OBJECTS) $(INCLUDES) 
  115.     cc -o $@ $(OBJECTS) $(LDFLAGS) 
  116.  
  117. .c.o:
  118.     cc -c $*.c $(CFLAGS) 
  119.  
  120. tags: $(CFILES) $(INCLUDES)
  121.     ctags -t $(INCLUDES) $(CFILES)
  122.  
  123. lint: 
  124.     lint -I$(INCDIR) $(CFILES)
  125.  
  126. man::
  127.     nroff -man xrobots.man
  128.  
  129. clean::
  130.     rm -f $(OBJECTS)
  131. SHAR_EOF
  132. if test 1092 -ne "`wc -c < 'Makefile.nonImake'`"
  133. then
  134.     echo shar: error transmitting "'Makefile.nonImake'" '(should have been 1092 characters)'
  135. fi
  136. fi # end of overwriting check
  137. echo shar: extracting "'README'" '(2510 characters)'
  138. if test -f 'README'
  139. then
  140.     echo shar: will not over-write existing file "'README'"
  141. else
  142. cat << \SHAR_EOF > 'README'
  143.  
  144. README -- xrobots version 1.0 -- Thu May 25 13:23:49 PDT 1989
  145.  
  146.   xrobots is a game that runs on X Windows.  It is based on /usr/games/robots 
  147. and on The New Daleks (Macintosh).  To create a runnable binary, type 
  148.     make -f Makefile.nonImake
  149. An Imakefile is also included.
  150.   
  151. Compile time parameters:  
  152.        MAXX, MAXY -- these control the number of 'cells' in the playfield.
  153.      the default is 35x20.  The realistic maximum these can be on a 
  154.      1152x900 screen (ie most sun 3/50's) is about 50x40.  With a larger 
  155.      playfield, the scores will be higher and the game length longer, but
  156.      some graphics will appear slower.  I'd be interested to see this 
  157.      running on a bigger engine to see the effects.  With a 35x20 
  158.      playfield, scores in the 6000 range can be achieved.
  159.  
  160.        MAXSCORES -- the number of high scores that you want to keep.
  161.      The default is 20.
  162.  
  163.        The defaults for the binary is /usr/games/xrobots and the score
  164.      file is /usr/games/lib/xrobots_scores.  The binary should have
  165.      write access to the high score file (xrobots will attempt to 
  166.      create this itself).  
  167.  
  168.   There is a little bsd-ish stuff in score.c.  flock is used to stop a race 
  169. condition.  If you don't have a bsd-like flock, you could probably 
  170. comment it out.  The race condition (multiple users writing to the 
  171. score file) is probably rare.
  172.  
  173.   xrobots has been tested on Sun 3/50's 3/60's 3/280's running the X11R3
  174. server.  Also, it has been compiled and tested on a Pyramid running X11R2. 
  175. (You'll have to comment out the references to XtNresize in score.c if you 
  176. want it to compile under release 2.)
  177.  
  178. BUGS
  179.  
  180.   The man page doesn't install by default.  You'll have to do that yourself,
  181. or if you are using imake, just remove the comments from the tail of the
  182. Imakefile.
  183.  
  184.   None known.  There is a nasty bug in the awm window manager
  185. that causes keypress events to be ignored.  It shows up now and then...
  186. rather than code around it, I prefer another window manager.
  187.  
  188. -----
  189.  
  190. This insomnia killer was written by:
  191.   Brian Warkentine (bwarkent@polyslo.CalPoly.EDU).
  192.  
  193.  Permission to use, copy, modify and distribute (without charge) this
  194.    software, documentation, images, etc. is granted, provided that this 
  195.    comment and the author's name is retained.  The author assumes no 
  196.    responsibility for lost sleep as a consequence of use of this software.
  197.  
  198.  Send comments, bug reports, etc. to bwarkent@polyslo.CalPoly.EDU.
  199.    (Soon to be at @Sun.COM, so if the previous address doesn't work,
  200.    try brian@csufres.CSUFresno.EDU.)
  201.  
  202. SHAR_EOF
  203. if test 2510 -ne "`wc -c < 'README'`"
  204. then
  205.     echo shar: error transmitting "'README'" '(should have been 2510 characters)'
  206. fi
  207. fi # end of overwriting check
  208. echo shar: extracting "'bitmaps.h'" '(6146 characters)'
  209. if test -f 'bitmaps.h'
  210. then
  211.     echo shar: will not over-write existing file "'bitmaps.h'"
  212. else
  213. cat << \SHAR_EOF > 'bitmaps.h'
  214. /*
  215.  * bitmaps.h  --  xrobots v1.0
  216.  */
  217.  
  218. /*----------------------------------------------------------------------*/
  219. /* playfield images */
  220.  
  221. #define Image_player_width 20
  222. #define Image_player_height 20
  223. static char Image_player_bits[] = {
  224.    0xc0, 0x1f, 0x00, 0x30, 0x60, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01,
  225.    0x42, 0x10, 0x02, 0xe2, 0x38, 0x02, 0x41, 0x10, 0x04, 0x01, 0x00, 0x04,
  226.    0x01, 0x00, 0x04, 0x11, 0x40, 0x04, 0x19, 0xc0, 0x04, 0x1d, 0xc0, 0x05,
  227.    0x31, 0x60, 0x04, 0xe2, 0x38, 0x02, 0xc2, 0x1f, 0x02, 0x84, 0x0f, 0x01,
  228.    0x08, 0x80, 0x00, 0x30, 0x60, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00};
  229.  
  230. #define Image_player_dead_width 20
  231. #define Image_player_dead_height 20
  232. static char Image_player_dead_bits[] = {
  233.    0xc0, 0x1f, 0x00, 0x30, 0x60, 0x00, 0x08, 0x80, 0x00, 0x04, 0x00, 0x01,
  234.    0x12, 0x45, 0x02, 0xa2, 0x28, 0x02, 0x41, 0x10, 0x04, 0xa1, 0x28, 0x04,
  235.    0x11, 0x45, 0x04, 0x01, 0x00, 0x04, 0x01, 0x00, 0x04, 0x01, 0x00, 0x04,
  236.    0x01, 0x00, 0x04, 0x02, 0x00, 0x02, 0xf2, 0x7f, 0x02, 0x04, 0x00, 0x01,
  237.    0x08, 0x80, 0x00, 0x30, 0x60, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00};
  238.  
  239. #define Image_robot_width 20
  240. #define Image_robot_height 20
  241. static char Image_robot_bits[] = {
  242.    0x00, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x10, 0x40, 0x00, 0xe8, 0xff, 0x00,
  243.    0x04, 0x38, 0x01, 0xfa, 0xff, 0x03, 0x42, 0x15, 0x02, 0xaa, 0xaa, 0x02,
  244.    0x4a, 0x95, 0x02, 0x8a, 0x8a, 0x02, 0x1a, 0xc5, 0x02, 0x2a, 0xa2, 0x02,
  245.    0x2a, 0xa0, 0x02, 0x2e, 0xa2, 0x03, 0x20, 0x22, 0x00, 0x20, 0x22, 0x00,
  246.    0x20, 0x22, 0x00, 0x20, 0x22, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00};
  247.  
  248. #ifdef HEAP_STYLE_1
  249. /* your choice of how you like your dead robots to look...*/
  250.  
  251. #define Image_heap_width 20
  252. #define Image_heap_height 20
  253. static char Image_heap_bits[] = {
  254.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  255.    0xe0, 0xff, 0x01, 0x20, 0x00, 0x03, 0xa0, 0xaa, 0x06, 0xff, 0x57, 0x0d,
  256.    0x01, 0xe8, 0x0a, 0x55, 0xf5, 0x0a, 0xa9, 0xfa, 0x0e, 0x55, 0xfd, 0x0a,
  257.    0xbf, 0xfe, 0x0e, 0x55, 0xfd, 0x0a, 0xab, 0x7a, 0x0e, 0x55, 0x75, 0x0a,
  258.    0xff, 0xea, 0x06, 0xe0, 0x5f, 0x03, 0xa0, 0xaa, 0x01, 0xe0, 0xff, 0x00};
  259.  
  260. #else
  261.  
  262. #define Image_heap_width 20
  263. #define Image_heap_height 20
  264. static char Image_heap_bits[] = {
  265.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  266.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  267.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x1e, 0x00,
  268.    0x00, 0x35, 0x00, 0x80, 0x5b, 0x00, 0xc0, 0xae, 0x00, 0xe0, 0xf5, 0x00,
  269.    0xb0, 0xaa, 0x01, 0xe8, 0x6f, 0x03, 0x7c, 0xfe, 0x03, 0x00, 0x00, 0x00};
  270.  
  271. #endif
  272.  
  273.  
  274. #define dot_width 16
  275. #define dot_height 16
  276. static char dot_bits[] = {
  277.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  278.    0x00, 0x06, 0x00, 0x09, 0x80, 0x10, 0x40, 0x20, 0x40, 0x20, 0x80, 0x10,
  279.    0x00, 0x09, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00};
  280.  
  281. /*----------------------------------------------------------------------*/
  282. /* cursors */
  283.  
  284. #define down_width 16
  285. #define down_height 16
  286. static char down_bits[] = {
  287.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01,
  288.    0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xb0, 0x0d,
  289.    0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00};
  290.  
  291. #define down_left_width 16
  292. #define down_left_height 16
  293. static char down_left_bits[] = {
  294.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  295.    0x00, 0x01, 0x80, 0x03, 0xc0, 0x01, 0xe6, 0x00, 0x76, 0x00, 0x3e, 0x00,
  296.    0x1e, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00};
  297.  
  298. #define down_right_width 16
  299. #define down_right_height 16
  300. static char down_right_bits[] = {
  301.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  302.    0x80, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x67, 0x00, 0x6e, 0x00, 0x7c,
  303.    0x00, 0x78, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00};
  304.  
  305. #define left_width 16
  306. #define left_height 16
  307. static char left_bits[] = {
  308.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00,
  309.    0x0c, 0x00, 0xfe, 0x07, 0xfe, 0x07, 0x0c, 0x00, 0x18, 0x00, 0x10, 0x00,
  310.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  311.  
  312. #define right_width 16
  313. #define right_height 16
  314. static char right_bits[] = {
  315.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x18,
  316.    0x00, 0x30, 0xe0, 0x7f, 0xe0, 0x7f, 0x00, 0x30, 0x00, 0x18, 0x00, 0x08,
  317.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  318.  
  319. #define up_width 16
  320. #define up_height 16
  321. static char up_bits[] = {
  322.    0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xb0, 0x0d, 0x80, 0x01,
  323.    0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00,
  324.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  325.  
  326. #define up_right_width 16
  327. #define up_right_height 16
  328. static char up_right_bits[] = {
  329.    0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x78, 0x00, 0x7c, 0x00, 0x6e,
  330.    0x00, 0x67, 0x80, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  331.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  332.  
  333.  
  334. #define up_left_width 16
  335. #define up_left_height 16
  336. static char up_left_bits[] = {
  337.    0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x76, 0x00,
  338.    0xe6, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  339.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  340.  
  341.  
  342. #define stay_width 16
  343. #define stay_height 16
  344. static char stay_bits[] = {
  345.    0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x10,
  346.    0x08, 0x18, 0x18, 0xfc, 0x3f, 0x18, 0x18, 0x10, 0x08, 0x01, 0x80, 0x03,
  347.    0xc0, 0x07, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01};
  348.  
  349.  
  350. #define cant_go_width 16
  351. #define cant_go_height 16
  352. static char cant_go_bits[] = {
  353.    0x00, 0x00, 0xc0, 0x07, 0x20, 0x08, 0x90, 0x13, 0x50, 0x12, 0x20, 0x12,
  354.    0x00, 0x09, 0x80, 0x04, 0x80, 0x02, 0x80, 0x02, 0x00, 0x01, 0x00, 0x01,
  355.    0x80, 0x02, 0x80, 0x02, 0x00, 0x01, 0x00, 0x00};
  356.  
  357.  
  358. #define thumbs_down_width 16
  359. #define thumbs_down_height 16
  360. #define thumbs_down_x_hot 7
  361. #define thumbs_down_y_hot 15
  362. static char thumbs_down_bits[] = {
  363.    0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0x1e, 0x40, 0x00, 0x78, 0x00, 0x80,
  364.    0x00, 0x78, 0x00, 0x80, 0x00, 0x7c, 0x0e, 0x40, 0x30, 0x3e, 0x40, 0x03,
  365.    0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0, 0x00};
  366. SHAR_EOF
  367. if test 6146 -ne "`wc -c < 'bitmaps.h'`"
  368. then
  369.     echo shar: error transmitting "'bitmaps.h'" '(should have been 6146 characters)'
  370. fi
  371. fi # end of overwriting check
  372. echo shar: extracting "'callbacks.c'" '(7742 characters)'
  373. if test -f 'callbacks.c'
  374. then
  375.     echo shar: will not over-write existing file "'callbacks.c'"
  376. else
  377. cat << \SHAR_EOF > 'callbacks.c'
  378. /*
  379.  * callbacks.c  --  xrobots v1.0
  380.  */
  381.  
  382. #include <X11/X.h>
  383. #include <X11/Intrinsic.h>
  384. #include <X11/StringDefs.h>
  385. #include <math.h>
  386. #include "game.h"
  387. #include "callbacks.h"
  388. #include "graphics.h"
  389.  
  390. extern Widget sonic_command;
  391.  
  392. /*----------------------------------------------------------------------*/
  393. /* Editorial note:  For most of the functions in this file, callbacks 
  394.  *     are nothing more than overgrown actions.  Both are used and
  395.  *    needed.  Unfortunately, there's alot of boilerplate overhead.
  396.  *     Actually, all this could be done without any callbacks.
  397.  */
  398.  
  399. /*ARGSUSED*/
  400. XtCallbackProc
  401. teleport_callback(widget,closure,callData)
  402.   Widget widget;
  403.   caddr_t closure;
  404.   caddr_t callData;
  405. {
  406.   teleport();
  407. }
  408.  
  409. /*ARGSUSED*/
  410. static XtActionProc
  411. teleport_action(w,event,params,num_params)
  412.   Widget w;
  413.   XEvent *event;
  414.   String *params;
  415.   Cardinal *num_params;
  416. {
  417.   teleport();
  418. }
  419.  
  420.  
  421. /*ARGSUSED*/
  422. XtCallbackProc
  423. wait_callback(widget,closure,callData)
  424.   Widget widget;
  425.   caddr_t closure;
  426.   caddr_t callData;
  427. {
  428.   wait_for_em();
  429. }
  430.  
  431.  
  432. /*ARGSUSED*/
  433. static XtActionProc
  434. wait_action(w,event,params,num_params)
  435.   Widget w;
  436.   XEvent *event;
  437.   String *params;
  438.   Cardinal *num_params;
  439. {
  440.   wait_for_em();
  441. }
  442.  
  443.  
  444.  
  445. /*ARGSUSED*/
  446. XtCallbackProc
  447. sonic_callback(widget,closure,callData)
  448.   Widget widget;
  449.   caddr_t closure;
  450.   caddr_t callData;
  451. {
  452.   static Arg arg = { XtNsensitive, False};
  453.   if(!game_active) return;
  454.   XtSetValues(sonic_command,&arg,1);
  455.   sonic_screwdriver();
  456. }
  457.  
  458. /*ARGSUSED*/
  459. static XtActionProc
  460. sonic_action(w,event,params,num_params)
  461.   Widget w;
  462.   XEvent *event;
  463.   String *params;
  464.   Cardinal *num_params;
  465. {
  466.   static Arg arg = { XtNsensitive, False};
  467.   if(!game_active) return;
  468.   XtSetValues(sonic_command,&arg,1);
  469.   sonic_screwdriver();
  470. }
  471.  
  472.  
  473. void
  474. reset_sonic_button()
  475. {
  476.   static Arg arg = { XtNsensitive, True };
  477.   XtSetValues(sonic_command,&arg,1);
  478. }
  479.  
  480.  
  481. /*ARGSUSED*/
  482. XtCallbackProc
  483. new_game_callback(widget,closure,callData)
  484.   Widget widget;
  485.   caddr_t closure;
  486.   caddr_t callData;
  487. {
  488.   new_game();
  489. }
  490.  
  491.  
  492. /*ARGSUSED*/
  493. static XtActionProc
  494. new_game_action(w,event,params,num_params)
  495.   Widget w;
  496.   XEvent *event;
  497.   String *params;
  498.   Cardinal *num_params;
  499. {
  500.   new_game();
  501. }
  502.  
  503.  
  504. /*ARGSUSED*/
  505. XtCallbackProc
  506. quit_callback(widget,closure,callData)
  507.   Widget widget;
  508.   caddr_t closure;
  509.   caddr_t callData;
  510. {
  511.  quit_game();
  512. }
  513.  
  514. /*ARGSUSED*/
  515. static XtActionProc
  516. quit_action(w,event,params,num_params)
  517.   Widget w;
  518.   XEvent *event;
  519.   String *params;
  520.   Cardinal *num_params;
  521. {
  522.   quit_game();
  523. }
  524.  
  525.  
  526. /*ARGSUSED*/
  527. static XtActionProc
  528. do_nothing_action(w,event,params,num_params)
  529.   Widget w;
  530.   XEvent *event;
  531.   String *params;
  532.   Cardinal *num_params;
  533. {
  534.   /* do nothing */
  535. }
  536.  
  537.  
  538.  
  539. /*----------------------------------------------------------------------*/
  540.  
  541.  
  542. int 
  543. determine_direction(button_x,button_y)
  544.   int button_x,button_y;
  545. {
  546. /* 
  547.  * Given the mouse's x&y position, this routine determines the direction
  548.  * relative to the player, and returns the result coded into a int.
  549.  */
  550.   float slope, invslope;
  551.   int direction = 0;
  552.   int coord_x = pos_to_coord(human_x) + CELLSIZE/2,
  553.       coord_y = pos_to_coord(human_y) + CELLSIZE/2;
  554.  
  555.   if( (abs(coord_x - button_x) < (CELLSIZE/2)+2) &&
  556.       (abs(coord_y - button_y) < (CELLSIZE/2)+2)) 
  557.     return(STILL);      /* cursor is directly over the player */ 
  558.  
  559.   if(button_x - coord_x != 0) {
  560.     slope = fabs((float)(button_y - coord_y) / (float)(button_x - coord_x)); 
  561.  
  562.     if( button_x > coord_x ) {            /* in coordinates 1 or 4 */
  563.       if( (slope < 2) && (human_x < MAXX) )
  564.         direction = RIGHT;
  565.     }
  566.     else                     /* in coordinates 2 or 3 */
  567.       if( (slope < 2) && (human_x > -1) )
  568.         direction = LEFT;
  569.   }
  570.  
  571.   if(button_y - coord_y != 0) {
  572.     invslope = fabs((float)(button_x - coord_x) / (float)(button_y - coord_y)); 
  573.  
  574.     if( button_y > coord_y ) {            /* in coordinates 1 or 2 */
  575.       if( (invslope < 2) && (human_y < MAXY) )
  576.         direction |= DOWN;
  577.     }
  578.  
  579.     else                     /* in coordinates 3 or 4 */
  580.       if( (invslope < 2) && (human_y > -1) )
  581.         direction |= UP;
  582.   }
  583.   return(direction);
  584. }
  585.  
  586.  
  587.  
  588. /*----------------------------------------------------------------------*/
  589.  
  590.  
  591. /*ARGSUSED*/
  592. static XtActionProc
  593. move_action(w,event,params,num_params)
  594.   Widget w;
  595.   XButtonEvent *event;
  596.   String *params;
  597.   Cardinal *num_params;
  598. {
  599. /* 
  600.  *  Called to move the player's icon.  This action can be called 
  601.  *  when a mouse button is pressed or when a key is pressed.
  602.  *  This is all dependent on the current translations.
  603.  */
  604.   int direction;
  605.   int tmp_human_x = human_x, tmp_human_y = human_y;
  606.   int num_wasted;
  607.   int param_count = *num_params;
  608.  
  609.   if(!game_active) return;
  610.  
  611.   if(!*num_params) {    /* no parameters - use the mouse pointer */
  612.  
  613.     direction = determine_direction(event->x,event->y);
  614.     if(!direction)  return;
  615.  
  616.     if(direction & UP)    tmp_human_y--;
  617.     if(direction & DOWN)  tmp_human_y++;
  618.     if(direction & LEFT)  tmp_human_x--;
  619.     if(direction & RIGHT) tmp_human_x++;
  620.  
  621.   } else 
  622.  
  623.     while(param_count--) {
  624.       /* else pull the direction out of the parameters. */
  625.       /* you can 'cheat' here... but who's gonna tell? */
  626.       if(!strcmp("right",*(params+param_count)))
  627.         tmp_human_x++;
  628.       if(!strcmp("left", *(params+param_count)))
  629.         tmp_human_x--;
  630.       if(!strcmp("up",   *(params+param_count)))
  631.         tmp_human_y--;
  632.       if(!strcmp("down", *(params+param_count)))
  633.         tmp_human_y++;
  634.     }
  635.  
  636.   last_human_x = human_x;
  637.   last_human_y = human_y;
  638.  
  639.   if( can_go(tmp_human_x,tmp_human_y) ) {
  640.     human_x = tmp_human_x;
  641.     human_y = tmp_human_y;
  642.     num_wasted = chase();
  643.     show_movement();
  644.     add_score(num_wasted);
  645.     if(!num_robots)
  646.       new_level();
  647.     else
  648.       display_possible_moves();
  649.     pointer_moved((Widget)0,(caddr_t)0,event);
  650.   }
  651.  
  652. }
  653.  
  654.  
  655.  
  656.  
  657. /*ARGSUSED*/
  658. static XtActionProc
  659. go_here_action(w,event,params,num_params)
  660.   Widget w;
  661.   XButtonEvent *event;
  662.   String *params;
  663.   Cardinal *num_params;
  664. {
  665. /* 
  666.  * This action causes player's icon to try to go to a spot in the 
  667.  * play area.  It stops if a move cannot be made.
  668.  */
  669.   int direction;
  670.   int tmp_human_x, tmp_human_y;
  671.   int num_wasted;
  672.  
  673.   if(!game_active) return;
  674.  
  675.   while(direction = determine_direction(event->x,event->y)) {
  676.     if(direction == STILL) break;
  677.     tmp_human_x = human_x;
  678.     tmp_human_y = human_y;
  679.  
  680.     if(direction & UP)    tmp_human_y--;
  681.     if(direction & DOWN)  tmp_human_y++;
  682.     if(direction & LEFT)  tmp_human_x--;
  683.     if(direction & RIGHT) tmp_human_x++;
  684.  
  685.     if( !can_go(tmp_human_x,tmp_human_y) ) 
  686.       break;
  687.     last_human_x = human_x;
  688.     last_human_y = human_y;
  689.     human_x = tmp_human_x;
  690.     human_y = tmp_human_y;
  691.     num_wasted = chase();
  692.     show_movement();
  693.     add_score(num_wasted);
  694.     if(!num_robots) {
  695.       new_level();
  696.       break;
  697.     }
  698.     if(spiffy) {
  699.       display_possible_moves();
  700.       pointer_moved((Widget)0,(caddr_t)0,event);
  701.     }
  702.   }
  703.   if(spiffy)
  704.     display_possible_moves();
  705.   pointer_moved((Widget)0,(caddr_t)0,event);
  706. }
  707.  
  708.  
  709.  
  710. /*ARGSUSED*/
  711. XtEventHandler
  712. pointer_moved(w, closure, event)
  713.   Widget w;
  714.   caddr_t closure;
  715.   XPointerMovedEvent *event;
  716. {
  717.   if(game_active) 
  718.     update_pointer( determine_direction(event->x,event->y) );
  719. }
  720.  
  721. /*----------------------------------------------------------------------*/
  722. /*----------------------------------------------------------------------*/
  723.  
  724. static XtActionsRec actions[] = {
  725.   {"wait",      (XtActionProc)wait_action},
  726.   {"teleport",  (XtActionProc)teleport_action},
  727.   {"sonic",     (XtActionProc)sonic_action},
  728.   {"move",      (XtActionProc)move_action},
  729.   {"go_here",   (XtActionProc)go_here_action},
  730.   {"quit",      (XtActionProc)quit_action},
  731.   {"new_game",  (XtActionProc)new_game_action},
  732.   {"do_nothing",(XtActionProc)do_nothing_action},
  733. };
  734.  
  735. void
  736. init_actions()
  737. {
  738.    XtAddActions(actions,XtNumber(actions));
  739. }
  740.  
  741.  
  742. SHAR_EOF
  743. if test 7742 -ne "`wc -c < 'callbacks.c'`"
  744. then
  745.     echo shar: error transmitting "'callbacks.c'" '(should have been 7742 characters)'
  746. fi
  747. fi # end of overwriting check
  748. echo shar: extracting "'callbacks.h'" '(309 characters)'
  749. if test -f 'callbacks.h'
  750. then
  751.     echo shar: will not over-write existing file "'callbacks.h'"
  752. else
  753. cat << \SHAR_EOF > 'callbacks.h'
  754. /*
  755.  * callbacks.h  --  xrobots v1.0
  756.  */
  757.  
  758. extern XtCallbackProc    teleport_callback(), 
  759.             wait_callback(), 
  760.             sonic_callback(), 
  761.             quit_callback(), 
  762.             new_game_callback();
  763.  
  764. extern XtEventHandler     pointer_moved();
  765.  
  766. extern void         reset_sonic_button(),
  767.             init_actions();
  768.  
  769. extern int          determine_direction();
  770.  
  771. SHAR_EOF
  772. if test 309 -ne "`wc -c < 'callbacks.h'`"
  773. then
  774.     echo shar: error transmitting "'callbacks.h'" '(should have been 309 characters)'
  775. fi
  776. fi # end of overwriting check
  777. echo shar: extracting "'game.c'" '(6373 characters)'
  778. if test -f 'game.c'
  779. then
  780.     echo shar: will not over-write existing file "'game.c'"
  781. else
  782. cat << \SHAR_EOF > 'game.c'
  783. /*
  784.  * game.c  --  xrobots v1.0
  785.  *
  786.  * Most of the game logic is here.  
  787.  */
  788.  
  789. #include "game.h"
  790. #include "score.h"
  791.  
  792. /* some of these are global */
  793. int human_x, human_y, last_human_x, last_human_y;
  794.  
  795. int robot_array[MAXX][MAXY],
  796.     robot_array_bak[MAXX][MAXY];    
  797.     /* These arrays are filled with the robots and the heaps 
  798.      * They do not include the player(human).
  799.      */
  800. int score;
  801. int num_robots;
  802. int level;
  803. int game_active;
  804. int sonic_used;
  805.  
  806. /*----------------------------------------------------------------------*/
  807. void
  808. new_game()
  809. {
  810.   score = 0;
  811.   level = 0;
  812.   sonic_used = 1;
  813.   game_active = 1;
  814.   new_level();
  815.   update_score(score);
  816. }
  817.  
  818. /*----------------------------------------------------------------------*/
  819. void
  820. add_score(n)
  821.   int n;
  822. {
  823.   score += 10 * n; /* ten points for each wasted robot. */
  824.   num_robots -= n;
  825.   if(n) update_score(score);
  826. }
  827.  
  828. /*----------------------------------------------------------------------*/
  829. void
  830. new_level()
  831. {
  832.   int x,y,tmp;
  833.  
  834.   reset_sonic_button();
  835.   if(!sonic_used) {
  836.     score += 50;     /* bonus for not using sonic screwdriver on last level*/
  837.     update_score(score);
  838.   }
  839.   sonic_used = 0;
  840.   level++;
  841.   num_robots = tmp = level*5;
  842.  
  843.   for_each                            /* clean out both the robot arrays */
  844.   {
  845.     robot_array[x][y] = EMPTY;
  846.     robot_array_bak[x][y] = EMPTY;
  847.   }
  848.   
  849.   human_x = (int)random()%MAXX;                  /* assign human to new space */
  850.   human_y = (int)random()%MAXY;
  851.   robot_array[human_x][human_y] = ROBOT;
  852.  
  853.   while(tmp--)
  854.   {
  855.     x = (int)random()%MAXX;
  856.     y = (int)random()%MAXY;
  857.     if(robot_array[x][y] == ROBOT) tmp++;        /* space already occupied */
  858.     robot_array[x][y] = ROBOT;
  859.   }
  860.   robot_array[human_x][human_y] = EMPTY;
  861.   display_level();
  862.   display_possible_moves();
  863. }
  864.  
  865. /*----------------------------------------------------------------------*/
  866. int
  867. chase()
  868. {
  869.   /* chase() returns the number of robots that were wasted in each call. */
  870.   /* after each call, be sure to check if all the robots are dead */
  871.   int x,y;
  872.   int newx,newy;
  873.   int num_wasted = 0;
  874.  
  875.   for_each
  876.   {
  877.     robot_array_bak[x][y] = robot_array[x][y];
  878.     if(robot_array[x][y] != HEAP)
  879.       robot_array[x][y] = 0;
  880.   }
  881.  
  882.   for_each
  883.   {
  884.     if(robot_array_bak[x][y] != ROBOT)
  885.       continue;
  886.  
  887.     if(x>human_x)                           /* move toward the human */
  888.       newx = x-1;
  889.     else  
  890.       if(x<human_x)
  891.         newx = x+1;
  892.       else
  893.         newx = x;
  894.  
  895.     if(y>human_y) 
  896.       newy = y-1;
  897.     else  
  898.       if(y<human_y)
  899.         newy = y+1;
  900.       else
  901.         newy = y;
  902.  
  903. #   ifdef DEBUG
  904.     printf("moving (%d,%d) to (%d,%d)\n",x,y,newx,newy);
  905. #   endif
  906.  
  907.     /* check to see if a robot or heap was already in that spot */
  908.     if(robot_array[newx][newy] == ROBOT)
  909.     {
  910.       robot_array[newx][newy] = HEAP;
  911.       num_wasted += 2;
  912.       continue;
  913.     }
  914.     if(robot_array[newx][newy] == HEAP)
  915.     {
  916.       num_wasted++;
  917.       continue;
  918.     }
  919.     /* move robot to new location */
  920.     robot_array[newx][newy] = ROBOT;
  921.   }
  922.   return(num_wasted);
  923. }
  924.  
  925. /*----------------------------------------------------------------------*/
  926. void
  927. undo_chase()
  928. {
  929.   int x,y;
  930.   for_each
  931.     robot_array[x][y] = robot_array_bak[x][y];
  932. }
  933.  
  934. /*----------------------------------------------------------------------*/
  935. void
  936. teleport()
  937. {
  938.   int num_wasted;
  939.  
  940.   if(!game_active) return;
  941.   do
  942.   {
  943.     human_x = (int)random()%MAXX;        /* pick a spot not already occupied */
  944.     human_y = (int)random()%MAXY;
  945.   }
  946.   while(robot_array[human_x][human_y] != EMPTY);
  947.  
  948.   show_teleport();
  949.  
  950.   num_wasted = chase();
  951.  
  952.   if(robot_array[human_x][human_y] != EMPTY)
  953.   {
  954.     /* death... */
  955.     undo_chase();    
  956.     /* it is a matter of preference to clear the screen when you die... */
  957.     display_level();
  958.     do_death();
  959.     check_score(score);
  960.     game_active = 0;
  961.     return;
  962.   }
  963.  
  964.   display_level();
  965.  
  966.   score += num_robots;       /* bonus for teleporting */
  967.   score += num_wasted * 10;  /* score for any that collided */
  968.   num_robots -= num_wasted;
  969.   update_score(score);
  970.  
  971.   if(!num_robots) 
  972.     new_level();
  973.   else 
  974.     display_possible_moves();
  975.  
  976. }
  977.  
  978. /*----------------------------------------------------------------------*/
  979. void
  980. sonic_screwdriver()
  981. {
  982.   /* remove the neighboring robots by calling chase(), then clear out */
  983.   /* the human's position of robots */
  984.   int num_wasted;
  985.  
  986.   if(!game_active) return;
  987.   if(sonic_used) return;
  988.   sonic_used = 1;
  989.   show_sonic();
  990.   num_wasted = chase();
  991.   if(robot_array[human_x][human_y] == ROBOT)
  992.     add_score(1);
  993.   robot_array[human_x][human_y] = EMPTY;
  994.  
  995.   last_human_x = human_x;
  996.   last_human_y = human_y;
  997.   show_movement();
  998.  
  999.   add_score(num_wasted);
  1000.   if(!num_robots) 
  1001.     new_level();
  1002.   else 
  1003.     display_possible_moves();
  1004. }
  1005.  
  1006. /*----------------------------------------------------------------------*/
  1007. void
  1008. wait_for_em()
  1009. {
  1010. /* call chase until any robot is breathing right down the human's neck  */
  1011.   int num_wasted;
  1012.  
  1013.   if(!game_active) return;
  1014.  
  1015.   for(;;)
  1016.   {
  1017.     num_wasted = chase();
  1018.     if(!num_robots)
  1019.     {
  1020.       add_score(num_wasted);
  1021.       new_level();
  1022.       break;
  1023.     }
  1024.     if(robot_array[human_x][human_y] != EMPTY)
  1025.     {
  1026.       /* backout of latest chase() and break loop */
  1027.       undo_chase();
  1028.       break;
  1029.     }
  1030.     add_score(num_wasted);
  1031.     show_movement();
  1032.   }
  1033.   display_possible_moves();
  1034. }
  1035.  
  1036. /*----------------------------------------------------------------------*/
  1037.  
  1038.  
  1039. int
  1040. can_go(x,y)
  1041.   int x,y;
  1042. {
  1043. /* check if (x,y) is a legit move. */
  1044.   if( INYRANGE(y-1) ) {
  1045.     if( INXRANGE(x-1) )
  1046.       if(robot_array[x-1][y-1] == ROBOT)  return 0;
  1047.     if( INXRANGE(x) )
  1048.       if(robot_array[x][y-1] == ROBOT)  return 0;
  1049.     if( INXRANGE(x+1) )
  1050.       if(robot_array[x+1][y-1] == ROBOT)  return 0;
  1051.   }
  1052.  
  1053.   if( INYRANGE(y) ) {
  1054.     if( INXRANGE(x-1) )
  1055.       if(robot_array[x-1][y] == ROBOT)  return 0;
  1056.     if( INXRANGE(x) ) {
  1057.       if(robot_array[x][y] == ROBOT)  return 0;
  1058.       if(robot_array[x][y] == HEAP)   return 0;
  1059.       }
  1060.     if( INXRANGE(x+1) )
  1061.       if(robot_array[x+1][y] == ROBOT)  return 0;
  1062.   }
  1063.  
  1064.   if( INYRANGE(y+1) ) {
  1065.     if( INXRANGE(x-1) )
  1066.       if(robot_array[x-1][y+1] == ROBOT)  return 0;
  1067.     if( INXRANGE(x) )
  1068.       if(robot_array[x][y+1] == ROBOT)  return 0;
  1069.     if( INXRANGE(x+1) )
  1070.       if(robot_array[x+1][y+1] == ROBOT)  return 0;
  1071.   }
  1072.  
  1073.   if( !INXRANGE(x) )  return 0;
  1074.   if( !INYRANGE(y) )  return 0;
  1075.  
  1076.   return 1;
  1077. }
  1078.  
  1079. /*----------------------------------------------------------------------*/
  1080.  
  1081. SHAR_EOF
  1082. if test 6373 -ne "`wc -c < 'game.c'`"
  1083. then
  1084.     echo shar: error transmitting "'game.c'" '(should have been 6373 characters)'
  1085. fi
  1086. fi # end of overwriting check
  1087. echo shar: extracting "'game.h'" '(934 characters)'
  1088. if test -f 'game.h'
  1089. then
  1090.     echo shar: will not over-write existing file "'game.h'"
  1091. else
  1092. cat << \SHAR_EOF > 'game.h'
  1093. /*
  1094.  * game.h  --  xrobots v1.0
  1095.  */
  1096.  
  1097. #ifndef MAXX
  1098. #     define     MAXX 35
  1099. #endif
  1100. #ifndef MAXY
  1101. #      define     MAXY 20
  1102. #endif
  1103.  
  1104. #define EMPTY     0
  1105. #define ROBOT     1
  1106. #define HEAP      2
  1107. #define REDRAW     3
  1108.  
  1109. #define LEFT    1
  1110. #define RIGHT   2
  1111. #define UP      4
  1112. #define DOWN    8
  1113. #define STILL   16
  1114.  
  1115. #define for_each    for(x=0;x<MAXX;x++) \
  1116.               for(y=0;y<MAXY;y++)
  1117.  
  1118. /* I know, I KNOW... global variables! */
  1119.  
  1120. extern int     human_x, human_y,
  1121.                last_human_x, last_human_y;
  1122.  
  1123. extern int    robot_array[MAXX][MAXY],
  1124.         robot_array_bak[MAXX][MAXY];
  1125.  
  1126. extern int     score;
  1127.         num_robots;
  1128.         game_active;
  1129.  
  1130. #define MIN(a,b) ((a<b)?a:b)
  1131. #define MAX(a,b) ((a>b)?a:b)
  1132.  
  1133. #define INXRANGE( _x_ )  (((_x_) >=0) && ((_x_)<MAXX))
  1134. #define INYRANGE( _y_ )  (((_y_) >=0) && ((_y_)<MAXY))
  1135.  
  1136. extern void     new_game(), 
  1137.         add_score(), 
  1138.         new_level();
  1139. extern int      chase();
  1140. extern void     undo_chase(), 
  1141.         teleport(), 
  1142.         sonic_screwdriver(), 
  1143.         wait_for_em();
  1144. extern int      can_go();
  1145.  
  1146.  
  1147.  
  1148.  
  1149. SHAR_EOF
  1150. if test 934 -ne "`wc -c < 'game.h'`"
  1151. then
  1152.     echo shar: error transmitting "'game.h'" '(should have been 934 characters)'
  1153. fi
  1154. fi # end of overwriting check
  1155. echo shar: extracting "'graphics.c'" '(12072 characters)'
  1156. if test -f 'graphics.c'
  1157. then
  1158.     echo shar: will not over-write existing file "'graphics.c'"
  1159. else
  1160. cat << \SHAR_EOF > 'graphics.c'
  1161. /*
  1162.  * graphics.c  --  xrobots v1.0
  1163.  */
  1164.  
  1165. #include <X11/X.h>
  1166. #include <X11/Intrinsic.h>
  1167. #include <X11/Shell.h>
  1168. #include "graphics.h"
  1169. #include "game.h"
  1170. #include "bitmaps.h"
  1171.  
  1172. static Pixmap playerP, dead_playerP, robotP, heapP, dotP;
  1173. static Cursor upC, up_rightC, rightC, down_rightC, downC, 
  1174.               down_leftC, leftC, up_leftC, stayC, cant_goC, thumbsC;
  1175.  
  1176. #define NUM_TMP_CURSOR_PIXMAPS 11
  1177. static Pixmap tmp_pixmap[NUM_TMP_CURSOR_PIXMAPS]; 
  1178.  
  1179. /*----------------------------------------------------------------------*/
  1180.  
  1181. void
  1182. init_pixmaps(top_shell)
  1183.   Widget top_shell;
  1184. {
  1185. /*
  1186.  * Let's make some pixmaps and some cursors.
  1187.  * And then let's set the iconpixmap.
  1188.  */
  1189.   Pixmap tmpP;
  1190.   XColor fgcolor,bgcolor;
  1191.   Arg arg;
  1192.  
  1193.   playerP = XCreateBitmapFromData(display,playfield, 
  1194.         Image_player_bits, Image_player_width, Image_player_height);
  1195.  
  1196.   dead_playerP = XCreateBitmapFromData(display,playfield, 
  1197.         Image_player_dead_bits, Image_player_dead_width, 
  1198.         Image_player_dead_height);
  1199.  
  1200.   robotP  = XCreateBitmapFromData(display,playfield, 
  1201.         Image_robot_bits, Image_robot_width, Image_robot_height);
  1202.  
  1203.   heapP   = XCreateBitmapFromData(display,playfield, 
  1204.         Image_heap_bits, Image_heap_width, Image_heap_height);
  1205.  
  1206.   dotP    = XCreateBitmapFromData(display,playfield, 
  1207.         dot_bits, dot_width, dot_height);
  1208.  
  1209. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  1210.  
  1211.   fgcolor.pixel = fg;
  1212.   bgcolor.pixel = bg;
  1213.   fgcolor.flags =  DoRed | DoGreen | DoBlue;
  1214.   bgcolor.flags =  DoRed | DoGreen | DoBlue;
  1215.   XQueryColor(display,DefaultColormapOfScreen(XtScreen(playfield_widget)), &fgcolor);
  1216.   XQueryColor(display,DefaultColormapOfScreen(XtScreen(playfield_widget)), &bgcolor);
  1217.  
  1218.  
  1219.   tmp_pixmap[0] = 
  1220.   tmpP = XCreateBitmapFromData(display,playfield, up_bits, 
  1221.                                   up_width, up_height);
  1222.   upC  = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1223.  
  1224.   tmp_pixmap[1] = 
  1225.   tmpP = XCreateBitmapFromData(display,playfield, up_right_bits, 
  1226.                                   up_right_width, up_right_height);
  1227.   up_rightC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1228.  
  1229.   tmp_pixmap[2] = 
  1230.   tmpP = XCreateBitmapFromData(display,playfield, right_bits, 
  1231.                                   right_width, right_height);
  1232.   rightC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1233.  
  1234.   tmp_pixmap[3] = 
  1235.   tmpP = XCreateBitmapFromData(display,playfield, down_right_bits, 
  1236.                                   down_right_width, down_right_height);
  1237.   down_rightC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1238.  
  1239.   tmp_pixmap[4] = 
  1240.   tmpP = XCreateBitmapFromData(display,playfield, down_bits, 
  1241.                                   down_width, down_height);
  1242.   downC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1243.  
  1244.   tmp_pixmap[5] = 
  1245.   tmpP = XCreateBitmapFromData(display,playfield, down_left_bits, 
  1246.                                   down_left_width, down_left_height);
  1247.   down_leftC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1248.  
  1249.   tmp_pixmap[6] = 
  1250.   tmpP = XCreateBitmapFromData(display,playfield, left_bits, 
  1251.                                   left_width, left_height);
  1252.   leftC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1253.  
  1254.   tmp_pixmap[7] = 
  1255.   tmpP = XCreateBitmapFromData(display,playfield, up_left_bits, 
  1256.                                   up_left_width, up_left_height);
  1257.   up_leftC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1258.  
  1259.   tmp_pixmap[8] = 
  1260.   tmpP = XCreateBitmapFromData(display,playfield, stay_bits, 
  1261.                                   stay_width, stay_height);
  1262.   stayC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1263.  
  1264.   tmp_pixmap[9] = 
  1265.   tmpP = XCreateBitmapFromData(display,playfield, cant_go_bits, 
  1266.                                   cant_go_width, cant_go_height);
  1267.   cant_goC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,8,8);
  1268.  
  1269.   tmp_pixmap[10] = 
  1270.   tmpP = XCreateBitmapFromData(display,playfield, thumbs_down_bits, 
  1271.                                   thumbs_down_width, thumbs_down_height);
  1272.   thumbsC = XCreatePixmapCursor(display, tmpP, tmpP, &fgcolor,&bgcolor,
  1273.                  thumbs_down_x_hot,thumbs_down_y_hot);
  1274.  
  1275.   XtSetArg(arg,XtNiconPixmap,robotP);
  1276.   XtSetValues(top_shell,&arg,1);
  1277. }
  1278.  
  1279. /*----------------------------------------------------------------------*/
  1280.  
  1281. static void
  1282. display_ok_move(x,y)
  1283.   int x,y;
  1284. {
  1285.  
  1286.   if(can_go(x,y))
  1287.             /* show the icon for a good move */
  1288.     XCopyPlane(display,dotP,playfield,gc,0,0,
  1289.                dot_width,dot_height,
  1290.                pos_to_coord(x),pos_to_coord(y),1);
  1291.   else
  1292.             /* or erase any previous dross */
  1293.     if( INXRANGE(x) && INYRANGE(y) && (robot_array[x][y] == EMPTY))
  1294.       XClearArea(display, playfield, 
  1295.                  pos_to_coord(x), pos_to_coord(y),
  1296.                  CELLSIZE, CELLSIZE, False);
  1297. }
  1298.  
  1299. void
  1300. display_possible_moves()
  1301. {
  1302.   if(!spiffy) return;
  1303.   display_ok_move( human_x-1,human_y-1 );
  1304.   display_ok_move( human_x  ,human_y-1 );
  1305.   display_ok_move( human_x+1,human_y-1 );
  1306.   display_ok_move( human_x-1,human_y   );
  1307.  
  1308.   display_ok_move( human_x+1,human_y   );
  1309.   display_ok_move( human_x-1,human_y+1 );
  1310.   display_ok_move( human_x  ,human_y+1 );
  1311.   display_ok_move( human_x+1,human_y+1 );
  1312. }
  1313.  
  1314.  
  1315. void
  1316. display_level()
  1317. {
  1318. /* Naive refresh algorithm.... */
  1319.   int x,y;
  1320.  
  1321.   XClearWindow(display,playfield);
  1322.   if(game_active)
  1323.     XCopyPlane(display,playerP,playfield,gc,0,0,
  1324.      Image_player_width,Image_player_height,
  1325.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1326.   else
  1327.     XCopyPlane(display,dead_playerP,playfield,gc,0,0,
  1328.      Image_player_dead_width,Image_player_dead_height,
  1329.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1330.  
  1331.   for(y=0;y<MAXY;y++)
  1332.   {
  1333.     for(x=0;x<MAXX;x++)
  1334.         switch (robot_array[x][y])
  1335.         {
  1336.           case ROBOT:
  1337.             XCopyPlane(display,robotP,playfield,gc,0,0,
  1338.                        Image_robot_width,Image_robot_height,
  1339.                        pos_to_coord(x),pos_to_coord(y),1);
  1340.             break;
  1341.  
  1342.           case HEAP:  
  1343.             XCopyPlane(display,heapP,playfield,gc,0,0,
  1344.                        Image_heap_width,Image_heap_height,
  1345.                        pos_to_coord(x),pos_to_coord(y),1);
  1346.             break;
  1347.     }
  1348.   }
  1349. }
  1350.  
  1351.  
  1352. void
  1353. show_movement()
  1354. {
  1355. /* 
  1356.  * draw just the changes.
  1357.  */
  1358.   int x,y;
  1359.  
  1360.   /* force a redraw of the area surrounding last position */
  1361.   for(x=last_human_x-1;x<last_human_x+2;x++)
  1362.     for(y=last_human_y-1;y<last_human_y+2;y++)
  1363.       if( INXRANGE(x) && INYRANGE(y) )
  1364.         robot_array_bak[x][y] = REDRAW;  
  1365.  
  1366.   /* 
  1367.    * This is a little hacked up because the player isn't really in the 
  1368.    * robot array.  Assigning the backup array to EMPTY avoids
  1369.    * drawing over the player.
  1370.    */
  1371.   robot_array_bak[human_x][human_y] = EMPTY;   
  1372.  
  1373.   XCopyPlane(display,playerP,playfield,gc,0,0,
  1374.         Image_player_width,Image_player_height,
  1375.         pos_to_coord(human_x),pos_to_coord(human_y),1);
  1376.  
  1377.   for(y=0;y<MAXY;y++)
  1378.   {
  1379.     for(x=0;x<MAXX;x++)
  1380.       if(robot_array[x][y] != robot_array_bak[x][y])
  1381.         switch (robot_array[x][y])
  1382.         {
  1383.           case ROBOT:
  1384.             XCopyPlane(display,robotP,playfield,gc,0,0,
  1385.                        Image_robot_width,Image_robot_height,
  1386.                        pos_to_coord(x),pos_to_coord(y),1);
  1387.             break;
  1388.  
  1389.           case HEAP:
  1390.             XCopyPlane(display,heapP,playfield,gc,0,0,
  1391.                        Image_heap_width,Image_heap_height,
  1392.                        pos_to_coord(x),pos_to_coord(y),1);
  1393.             break;
  1394.           default:
  1395.             XClearArea(display, playfield, 
  1396.                        pos_to_coord(x), pos_to_coord(y),
  1397.                        CELLSIZE, CELLSIZE, False);
  1398.     }
  1399.   }
  1400. }
  1401.  
  1402.  
  1403.  
  1404. /*ARGSUSED*/
  1405. XtEventHandler
  1406. redisplay_level(w, closure, event)
  1407.   Widget w;
  1408.   caddr_t closure;
  1409.   XExposeEvent *event;
  1410. {
  1411. /* refresh entire screen -- e.g. expose events.  Just a little naive. */
  1412.   display_level();
  1413.   display_possible_moves();
  1414. }
  1415.  
  1416.  
  1417. void
  1418. update_pointer(direction)
  1419.   int direction;
  1420. {
  1421. /*
  1422.  * set the cursor to the appropriate one.
  1423.  */
  1424.   int tmp_human_x = human_x, tmp_human_y = human_y;
  1425.  
  1426.   if(direction & UP)    tmp_human_y--;
  1427.   if(direction & DOWN)  tmp_human_y++;
  1428.   if(direction & LEFT)  tmp_human_x--;
  1429.   if(direction & RIGHT) tmp_human_x++;
  1430.  
  1431.   if(!can_go(tmp_human_x,tmp_human_y)) {
  1432.     XDefineCursor(display,playfield,cant_goC);
  1433.     return;
  1434.     }
  1435.   if(direction&LEFT)
  1436.     if(direction&UP)
  1437.       XDefineCursor(display,playfield,up_leftC);
  1438.     else 
  1439.       if(direction&DOWN)
  1440.           XDefineCursor(display,playfield,down_leftC);
  1441.       else
  1442.         XDefineCursor(display,playfield,leftC);
  1443.  
  1444.    if(direction&RIGHT)
  1445.     if(direction&UP)
  1446.       XDefineCursor(display,playfield,up_rightC);
  1447.     else 
  1448.       if(direction&DOWN)
  1449.           XDefineCursor(display,playfield,down_rightC);
  1450.       else
  1451.         XDefineCursor(display,playfield,rightC);
  1452.  
  1453.   if(direction == UP)
  1454.         XDefineCursor(display,playfield,upC);
  1455.   if(direction == DOWN)
  1456.         XDefineCursor(display,playfield,downC);
  1457.   if(direction == STILL)
  1458.         XDefineCursor(display,playfield,stayC);
  1459.     
  1460.  
  1461. }
  1462.  
  1463.  
  1464. /*----------------------------------------------------------------------*/
  1465.  
  1466. void free_pixmaps()
  1467. {
  1468.   int i;
  1469.  
  1470.   XFreeCursor(display,upC);
  1471.   XFreeCursor(display,up_rightC);
  1472.   XFreeCursor(display,rightC);
  1473.   XFreeCursor(display,down_rightC);
  1474.   XFreeCursor(display,downC);
  1475.   XFreeCursor(display,down_leftC);
  1476.   XFreeCursor(display,leftC); 
  1477.   XFreeCursor(display,up_leftC); 
  1478.   XFreeCursor(display,stayC);
  1479.   XFreeCursor(display,thumbsC);
  1480.   XFreeCursor(display,cant_goC);
  1481.   for(i=0;i++;i<NUM_TMP_CURSOR_PIXMAPS) 
  1482.     XFreePixmap(display,tmp_pixmap[i]);
  1483.  
  1484.   XFreePixmap(display,playerP);
  1485.   XFreePixmap(display,dead_playerP);
  1486.   XFreePixmap(display,robotP);
  1487.   XFreePixmap(display,heapP);
  1488.   XFreePixmap(display,dotP);
  1489.  
  1490. }
  1491.  
  1492.  
  1493.  
  1494. /*----------------------------------------------------------------------*/
  1495.  
  1496. void
  1497. do_death()
  1498. {
  1499.   XDefineCursor(display,playfield,thumbsC);
  1500.   XCopyPlane(display,dead_playerP,playfield,gc,0,0,
  1501.      Image_player_dead_width,Image_player_dead_height,
  1502.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1503. }
  1504.  
  1505. /*----------------------------------------------------------------------*/
  1506.  
  1507. void
  1508. show_teleport()
  1509. {
  1510. /* 
  1511.  * This may need to be slowed down (or changed) if you have a fast server.
  1512.  * Looks okay on a sun 3/50.
  1513.  */
  1514. unsigned int i;
  1515.  
  1516.   if(!spiffy) return;
  1517.  
  1518.   for(i=100;i>0;i-=25)
  1519.     XDrawArc(display,playfield,gc,
  1520.       pos_to_coord(human_x)+(CELLSIZE/2)-(i/2)-2,
  1521.       pos_to_coord(human_y)+(CELLSIZE/2)-(i/2)-2,
  1522.       i,i,0,0);
  1523. }
  1524.  
  1525. /*----------------------------------------------------------------------*/
  1526.  
  1527. static void
  1528. do_sonic(agc)
  1529. GC agc;
  1530. {
  1531. /* 
  1532.  * do some effects for the sonic screwdriver...
  1533.  */
  1534. #define SPACING 3
  1535. int center_x = pos_to_coord(human_x)+(CELLSIZE/2)-2,
  1536.     center_y = pos_to_coord(human_y)+(CELLSIZE/2)-2;
  1537. int i;
  1538.  
  1539.   if(!spiffy) return;
  1540.  
  1541.   for(i=pos_to_coord(human_x-1);i<pos_to_coord(human_x+2);i+=SPACING) {
  1542.     XDrawLine(display,playfield,agc,center_x,center_y,i,pos_to_coord(human_y-1));
  1543.     XCopyPlane(display,playerP,playfield,gc,0,0,
  1544.      Image_player_width,Image_player_height,
  1545.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1546.   }
  1547.  
  1548.   for(i=pos_to_coord(human_y-1);i<pos_to_coord(human_y+2);i+=SPACING) {
  1549.     XDrawLine(display,playfield,agc,center_x,center_y,pos_to_coord(human_x+2),i);
  1550.     XCopyPlane(display,playerP,playfield,gc,0,0,
  1551.      Image_player_width,Image_player_height,
  1552.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1553.   }
  1554.  
  1555.   for(i=pos_to_coord(human_x+2);i>pos_to_coord(human_x-1);i-=SPACING) {
  1556.     XDrawLine(display,playfield,agc,center_x,center_y,i,pos_to_coord(human_y+2));
  1557.     XCopyPlane(display,playerP,playfield,gc,0,0,
  1558.      Image_player_width,Image_player_height,
  1559.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1560.   }
  1561.  
  1562.   for(i=pos_to_coord(human_y+2);i>pos_to_coord(human_y-1);i-=SPACING) {
  1563.     XDrawLine(display,playfield,agc,center_x,center_y,pos_to_coord(human_x-1),i);
  1564.     XCopyPlane(display,playerP,playfield,gc,0,0,
  1565.      Image_player_width,Image_player_height,
  1566.      pos_to_coord(human_x),pos_to_coord(human_y),1);
  1567.   }
  1568. }
  1569.  
  1570.  
  1571. void
  1572. show_sonic()
  1573. {
  1574.   do_sonic(gc);        /* do it, */
  1575.   do_sonic(cleargc);    /* then erase it. */
  1576. }
  1577.  
  1578. SHAR_EOF
  1579. if test 12072 -ne "`wc -c < 'graphics.c'`"
  1580. then
  1581.     echo shar: error transmitting "'graphics.c'" '(should have been 12072 characters)'
  1582. fi
  1583. fi # end of overwriting check
  1584. echo shar: extracting "'graphics.h'" '(593 characters)'
  1585. if test -f 'graphics.h'
  1586. then
  1587.     echo shar: will not over-write existing file "'graphics.h'"
  1588. else
  1589. cat << \SHAR_EOF > 'graphics.h'
  1590. /*
  1591.  * graphics.h  --  xrobots v1.0
  1592.  */
  1593.  
  1594.  /* some of these are instanciated in main.c! */
  1595. extern Display     *display;
  1596. extern Window     playfield;
  1597. extern Widget     playfield_widget;
  1598. extern GC     gc,
  1599.         cleargc;
  1600. extern Pixel     fg, 
  1601.         bg;
  1602. extern Boolean     spiffy;
  1603.  
  1604. extern void     update_score();
  1605.  
  1606. extern XtEventHandler redisplay_level();
  1607.  
  1608. extern void     init_pixmaps(), 
  1609.         display_possible_moves(), 
  1610.         display_level(), 
  1611.         update_pointer(), 
  1612.         free_pixmaps(), 
  1613.         do_death(), 
  1614.         show_teleport(), 
  1615.         show_sonic(), 
  1616.         show_movement();
  1617.  
  1618. #define CELLSIZE 21
  1619.  
  1620. #define pos_to_coord( _pos_ ) (( _pos_ ) * CELLSIZE + 5)
  1621.  
  1622.  
  1623. SHAR_EOF
  1624. if test 593 -ne "`wc -c < 'graphics.h'`"
  1625. then
  1626.     echo shar: error transmitting "'graphics.h'" '(should have been 593 characters)'
  1627. fi
  1628. fi # end of overwriting check
  1629. echo shar: extracting "'help.c'" '(3628 characters)'
  1630. if test -f 'help.c'
  1631. then
  1632.     echo shar: will not over-write existing file "'help.c'"
  1633. else
  1634. cat << \SHAR_EOF > 'help.c'
  1635. /*
  1636.  * help.c  --  xrobots v1.0
  1637.  */
  1638.  
  1639. #include <X11/Intrinsic.h>
  1640. #include <X11/StringDefs.h>
  1641. #include <X11/Shell.h>
  1642. #include <X11/AsciiText.h>
  1643. #include <X11/Command.h>
  1644. #include <X11/Box.h>
  1645. #include "help.h"
  1646.  
  1647. /*----------------------------------------------------------------------*/
  1648.  
  1649. Widget help_popup;
  1650.  
  1651. static Arg arglist_text[] = {
  1652.   {  XtNheight, (XtArgVal) 300   },
  1653.   {  XtNtextOptions, (XtArgVal) scrollVertical },
  1654.   {  XtNwidth, (XtArgVal) 505 },
  1655.   {  XtNstring, (XtArgVal) "\
  1656. xrobots -- version 1.0\n\
  1657. \n\
  1658. Welcome to the world of xrobots.  Where the bad guys (the robots) are \n\
  1659. incredibly stupid and the good guy (the smiley face) is outnumbered.\n\
  1660. You (as the good guy) can avoid death and achieve instant fame and \n\
  1661. gratification by appropriate use of the mouse and/or keyboard.\n\
  1662. \n\
  1663. The mouse:  \n\
  1664. Clicking the left mouse button moves the smiley face one step in the \n\
  1665. direction of the pointer.  Clicking directly on top of the smiley face \n\
  1666. takes a turn, but does not change it's position.  \n\
  1667. \n\
  1668. Clicking the middle mouse button causes the smiley face to run like heck. \n\
  1669. Of course, the robots can run just as fast so it really doesn't matter... \n\
  1670. Or does it? \n\
  1671. \n\
  1672. Clicking the right mouse button gives the smiley a rest.  This is the \n\
  1673. same as clicking on the 'wait' button.\n\
  1674. \n\
  1675. \n\
  1676. The keyboard: \n\
  1677.     's' triggers the sonic screwdriver. \n\
  1678.     't' triggers the teleportation device. \n\
  1679.     'w' waits until robots are breathing down your neck. \n\
  1680.     '.' waits one turn. \n\
  1681. \n\
  1682.      Directional control:\n\
  1683. \n\
  1684.          y k u \n\
  1685.           \\|/  \n\
  1686.          h- -l \n\
  1687.           /|\\  \n\
  1688.          b j n \n\
  1689. \n\
  1690. \n\
  1691. Well, that's the low down.  If you don't like the mouse or keyboard set up,\n\
  1692. see the manual to find out about changing the translations.  \n\
  1693. \n\
  1694. ----\n\
  1695. \n\
  1696. This insomnia killer was written by:\n\
  1697.   Brian Warkentine (bwarkent@polyslo.CalPoly.EDU).\n\
  1698. \n\ "
  1699.   },
  1700.   {  XtNeditType, (XtArgVal) XttextRead  },
  1701. };
  1702.  
  1703.  
  1704. static Arg arglist_popdown[] = {
  1705.   {  XtNresize, (XtArgVal) False  },
  1706.   {  XtNwidth, (XtArgVal) 300   },
  1707.   {  XtNlabel, (XtArgVal) "Pop Down"  },
  1708.   {  XtNjustify, (XtArgVal) XtJustifyCenter  },
  1709. };
  1710.  
  1711.  
  1712. /*ARGSUSED*/
  1713. static XtCallbackProc 
  1714. popdown_callback(w, closure, call_data)
  1715.   Widget w;
  1716.   caddr_t closure;
  1717.   caddr_t call_data;
  1718. {
  1719.   XtPopdown(help_popup);
  1720. }
  1721.  
  1722.  
  1723. void
  1724. create_help_popup(parent)
  1725.   Widget parent;
  1726. {
  1727.   int i;
  1728.   Widget help_box, popdown;
  1729.  
  1730.   help_popup = XtCreatePopupShell(
  1731.                                    "help_popup",
  1732.                                    transientShellWidgetClass,
  1733.                                    parent, 0,0);
  1734.  
  1735.   help_box = XtCreateManagedWidget(
  1736.                                     "help_box",
  1737.                                     boxWidgetClass,
  1738.                                     help_popup,
  1739.                                     0,0);
  1740.  
  1741.   (void) XtCreateManagedWidget(
  1742.                                     "message",
  1743.                                     asciiStringWidgetClass,
  1744.                                     help_box,
  1745.                                     arglist_text,
  1746.                                     XtNumber(arglist_text));
  1747.  
  1748.   popdown = XtCreateManagedWidget(
  1749.                                     "popdown",
  1750.                                     commandWidgetClass,
  1751.                                     help_box,
  1752.                                     arglist_popdown,
  1753.                                     XtNumber(arglist_popdown));
  1754.   XtAddCallback(popdown,XtNcallback,popdown_callback,0);
  1755. }
  1756.  
  1757.  
  1758.  
  1759. /*ARGSUSED*/
  1760. XtCallbackProc
  1761. show_help_callback(widget,closure,callData)
  1762.   Widget widget;
  1763.   caddr_t closure;
  1764.   caddr_t callData;
  1765. {
  1766.   XtPopup(help_popup, XtGrabNone);
  1767. }
  1768.  
  1769.  
  1770.  
  1771. SHAR_EOF
  1772. if test 3628 -ne "`wc -c < 'help.c'`"
  1773. then
  1774.     echo shar: error transmitting "'help.c'" '(should have been 3628 characters)'
  1775. fi
  1776. fi # end of overwriting check
  1777. echo shar: extracting "'help.h'" '(116 characters)'
  1778. if test -f 'help.h'
  1779. then
  1780.     echo shar: will not over-write existing file "'help.h'"
  1781. else
  1782. cat << \SHAR_EOF > 'help.h'
  1783. /*
  1784.  * help.h  --  xrobots v1.0
  1785.  */
  1786.  
  1787. extern void         create_help_popup();
  1788. extern XtCallbackProc    show_help_callback();
  1789.  
  1790. SHAR_EOF
  1791. if test 116 -ne "`wc -c < 'help.h'`"
  1792. then
  1793.     echo shar: error transmitting "'help.h'" '(should have been 116 characters)'
  1794. fi
  1795. fi # end of overwriting check
  1796. echo shar: extracting "'main.c'" '(8713 characters)'
  1797. if test -f 'main.c'
  1798. then
  1799.     echo shar: will not over-write existing file "'main.c'"
  1800. else
  1801. cat << \SHAR_EOF > 'main.c'
  1802. /*
  1803.  * main.c  --  xrobots v1.0
  1804.  * 
  1805.  * Author: Brian Warkentine, 1989.
  1806.  *
  1807.  * Permission to use, copy, modify and distribute (without charge) this
  1808.  *   software, documentation, images, etc. is granted, provided that this 
  1809.  *   comment and the author's name is retained.  The author assumes no 
  1810.  *   responsibility for lost sleep as a consequence of use of this software.
  1811.  *
  1812.  * Send comments, bug reports, etc. to bwarkent@polyslo.CalPoly.EDU.
  1813.  *   (Soon to be at @Sun.COM, so if the previous address doesn't work,
  1814.  *   try brian@csufres.CSUFresno.EDU.)
  1815.  *
  1816.  * Portions of this code generated by wedgimatic on Jan 21 14:24:10 PST 1989.
  1817.  * 
  1818.  */
  1819.  
  1820. #include <X11/X.h>
  1821. #include <X11/Intrinsic.h>
  1822. #include <X11/StringDefs.h>
  1823. #include <X11/cursorfont.h>
  1824. #include <X11/Core.h>
  1825. #include <X11/Label.h>
  1826. #include <X11/Command.h>
  1827. #include <X11/Box.h>
  1828.  
  1829. #include "callbacks.h"
  1830. #include "graphics.h"
  1831. #include "game.h"
  1832. #include "score.h"
  1833. #include "help.h"
  1834.  
  1835. /*----------------------------------------------------------------------*/
  1836.  
  1837. Widget top_shell, top_widget, playfield_widget, score_widget, sonic_command;
  1838.  
  1839. Display *display;
  1840. Window playfield;
  1841.  
  1842. GC gc;
  1843. GC cleargc;
  1844.  
  1845. /*----------------------------------------------------------------------*/
  1846.  
  1847.  
  1848. static XtCallbackRec teleport_callbackList[] = {
  1849.   {  (XtCallbackProc)teleport_callback, NULL  },
  1850.   {  NULL, NULL  }
  1851. };
  1852.  
  1853. static XtCallbackRec wait_callbackList[] = {
  1854.   {  (XtCallbackProc)wait_callback, NULL  },
  1855.   {  NULL, NULL  }
  1856. };
  1857.  
  1858. static XtCallbackRec sonic_callbackList[] = {
  1859.   {  (XtCallbackProc)sonic_callback, NULL  },
  1860.   {  NULL, NULL  }
  1861. };
  1862.  
  1863. static XtCallbackRec quitList[] = {
  1864.   {  (XtCallbackProc)quit_callback, NULL  },
  1865.   {  NULL, NULL  }
  1866. };
  1867.  
  1868. static XtCallbackRec new_gameList[] = {
  1869.   {  (XtCallbackProc)new_game_callback, NULL  },
  1870.   {  NULL, NULL  }
  1871. };
  1872.  
  1873. static XtCallbackRec show_helpList[] = {
  1874.   {  (XtCallbackProc)show_help_callback, NULL  },
  1875.   {  NULL, NULL  }
  1876. };
  1877.  
  1878. /*----------------------------------------------------------------------*/
  1879.  
  1880.  
  1881. static Arg arglistplayfield[] = {
  1882.   {  XtNheight, (XtArgVal) pos_to_coord(MAXY)  },
  1883.   {  XtNwidth,  (XtArgVal) pos_to_coord(MAXX)  },
  1884.   {  XtNborderWidth, (XtArgVal) 4 },
  1885. };
  1886.  
  1887. static Arg arglistteleport_command[] = {
  1888.   {  XtNlabel, (XtArgVal) "Teleport"  },
  1889.   {  XtNcallback, (XtArgVal) teleport_callbackList }
  1890. };
  1891.  
  1892. static Arg arglistwait_command[] = {
  1893.   {  XtNlabel, (XtArgVal) "Wait"  },
  1894.   {  XtNcallback, (XtArgVal) wait_callbackList }
  1895. };
  1896.  
  1897. static Arg arglistsonic_command[] = {
  1898.   {  XtNlabel, (XtArgVal) "Sonic Screwdriver"  },
  1899.   {  XtNcallback, (XtArgVal) sonic_callbackList }
  1900. };
  1901.  
  1902. static Arg arglistquit_command[] = {
  1903.   {  XtNlabel, (XtArgVal) "Quit"  }, 
  1904.   {  XtNcallback, (XtArgVal) quitList }
  1905. };
  1906.  
  1907. static Arg arglistnew_game[] = {
  1908.   {  XtNlabel, (XtArgVal) "New Game"  }, 
  1909.   {  XtNcallback, (XtArgVal) new_gameList }
  1910. };
  1911.  
  1912. static Arg arglistscore_widget[] = {
  1913.   {  XtNlabel, (XtArgVal) "Score:    0"  }, 
  1914. };
  1915.  
  1916. static Arg arglisthelp_button[] = {
  1917.   {  XtNlabel, (XtArgVal) "Help"  }, 
  1918.   {  XtNcallback, (XtArgVal) show_helpList }
  1919. };
  1920.  
  1921. /*----------------------------------------------------------------------*/
  1922.  
  1923. /* these can be overriden -- of course */
  1924. static char translations_str[] = 
  1925.   "<Btn1Down>:    do_nothing()        \n\
  1926.    <Btn2Down>:    do_nothing()        \n\
  1927.    <Btn3Down>:    do_nothing()        \n\
  1928.    <Btn1Up>:    move()            \n\
  1929.    <Key>u:      move(right, up)        \n\
  1930.    <Key>l:      move(right)        \n\
  1931.    <Key>n:      move(right, down)    \n\
  1932.    <Key>y:      move(left, up)        \n\
  1933.    <Key>h:      move(left)        \n\
  1934.    <Key>b:      move(left, down)    \n\
  1935.    <Key>k:      move(up)        \n\
  1936.    <Key>j:      move(down)        \n\
  1937.    <Key>.:      move(nowhere)        \n\
  1938.    <Key>\\ :    move(nowhere)        \n\
  1939.    <Btn2Up>:    go_here()         \n\
  1940.    <Btn3Up>:    wait()             \n\
  1941.    <Key>s:      sonic()            \n\
  1942.    <Key>t:      teleport()         \n\
  1943.    <Key>w:      wait()            \n\
  1944.    <Key>z:      new_game()        ";
  1945. /* <Key>q:      quit() "; */
  1946.  
  1947. Pixel fg, bg;
  1948. Boolean spiffy;
  1949. XtTranslations translations;
  1950.  
  1951. static XtResource application_resources[] = {
  1952.   {"foreground", "Foreground", XtRPixel, sizeof(Pixel),
  1953.                 (Cardinal)&fg, XtRString, (caddr_t) "Black"},
  1954.   {"background", "Background", XtRPixel, sizeof(Pixel),
  1955.                 (Cardinal)&bg, XtRString, (caddr_t) "White"},
  1956.   {"spiffy", "Spiffy", XtRBoolean, sizeof(Boolean),
  1957.                 (Cardinal)&spiffy, XtRString, (caddr_t) "True"},
  1958.   {"translations","Translations", XtRTranslationTable, sizeof(XtTranslations),
  1959.                 (Cardinal)&translations, XtRString, (caddr_t)translations_str},
  1960. };
  1961.  
  1962. /*----------------------------------------------------------------------*/
  1963.  
  1964. main(argc, argv)
  1965.   unsigned int argc;
  1966.   char **argv;
  1967. {
  1968.   Arg args[1];
  1969.   XGCValues gcv;
  1970.  
  1971.   srandom(getpid());
  1972.  
  1973.   top_shell = XtInitialize(argv[0], "xrobots", 0, 0, &argc, argv);
  1974.  
  1975.   init_actions();
  1976.  
  1977.   XtGetApplicationResources(top_shell, 0, application_resources, 
  1978.             XtNumber(application_resources), NULL, 0 );
  1979.  
  1980.   top_widget = XtCreateManagedWidget(
  1981.                                     "top_widget",
  1982.                                     boxWidgetClass,
  1983.                                     top_shell,
  1984.                                     0,0);
  1985.  
  1986.   playfield_widget = XtCreateManagedWidget(
  1987.                                     "playfield",
  1988.                                     widgetClass,
  1989.                                     top_widget,
  1990.                                     arglistplayfield,
  1991.                                     XtNumber(arglistplayfield));
  1992.  
  1993.   XtAugmentTranslations(playfield_widget,translations);
  1994.  
  1995.   (void) XtCreateManagedWidget(
  1996.                                     "teleport_button",
  1997.                                     commandWidgetClass,
  1998.                                     top_widget,
  1999.                                     arglistteleport_command,
  2000.                                     XtNumber(arglistteleport_command));
  2001.  
  2002.   (void) XtCreateManagedWidget(
  2003.                                     "wait_button",
  2004.                                     commandWidgetClass,
  2005.                                     top_widget,
  2006.                                     arglistwait_command,
  2007.                                     XtNumber(arglistwait_command));
  2008.  
  2009.   sonic_command= XtCreateManagedWidget(
  2010.                                     "sonic_button",
  2011.                                     commandWidgetClass,
  2012.                                     top_widget,
  2013.                                     arglistsonic_command,
  2014.                                     XtNumber(arglistsonic_command));
  2015.  
  2016.   (void) XtCreateManagedWidget(
  2017.                                     "quit_button",
  2018.                                     commandWidgetClass,
  2019.                                     top_widget,
  2020.                                     arglistquit_command,
  2021.                                     XtNumber(arglistquit_command));
  2022.   (void) XtCreateManagedWidget(
  2023.                                     "new_game_button",
  2024.                                     commandWidgetClass,
  2025.                                     top_widget,
  2026.                                     arglistnew_game,
  2027.                                     XtNumber(arglistnew_game));
  2028.  
  2029.   (void) XtCreateManagedWidget(
  2030.                                     "help_button",
  2031.                                     commandWidgetClass,
  2032.                                     top_widget,
  2033.                                     arglisthelp_button,
  2034.                     XtNumber(arglisthelp_button));
  2035.  
  2036.   score_widget = XtCreateManagedWidget(
  2037.                                     "score_button",
  2038.                                     labelWidgetClass,
  2039.                                     top_widget,
  2040.                                     arglistscore_widget,
  2041.                                     XtNumber(arglistscore_widget));
  2042.  
  2043.  
  2044.   create_high_score_popup(top_widget);
  2045.   create_help_popup(top_widget);
  2046.  
  2047.   XtRealizeWidget(top_shell);
  2048.  
  2049.   display   = XtDisplay(playfield_widget);
  2050.   playfield = XtWindow(playfield_widget);
  2051.   gcv.foreground = fg;
  2052.   gcv.background = bg;
  2053.   gcv.function = GXcopy;
  2054.   gc = XCreateGC(display, playfield, 
  2055.          GCForeground | GCBackground | GCFunction, &gcv);
  2056.   gcv.foreground = bg;
  2057.   cleargc = XCreateGC(display, playfield,
  2058.           GCForeground | GCBackground | GCFunction, &gcv);
  2059.  
  2060.   XtAddEventHandler(playfield_widget, ExposureMask, 0, redisplay_level, 0);
  2061.   XtAddEventHandler(playfield_widget, PointerMotionMask, 0, pointer_moved, 0);
  2062.  
  2063.   init_pixmaps(top_shell);
  2064.  
  2065.   new_game();
  2066.  
  2067.   XtMainLoop();
  2068.  
  2069. }
  2070.  
  2071.  
  2072. void
  2073. quit_game()
  2074. {
  2075.   free_pixmaps();
  2076.   XtDestroyWidget(top_shell);
  2077.   XFreeGC(display,gc);
  2078.   XFreeGC(display,cleargc);
  2079.  
  2080. /*  XtDestroyApplicationContext(); */
  2081.   exit(0);
  2082. }
  2083.  
  2084.  
  2085. void
  2086. update_score(score)
  2087.   int score;
  2088. {
  2089.   char text[13];
  2090.   (void)sprintf(text,"Score: %4d",score);
  2091.   XtSetArg(arglistscore_widget[0],XtNlabel,text);
  2092.   XtSetValues(score_widget,arglistscore_widget,1);
  2093. }
  2094.  
  2095.  
  2096.  
  2097. SHAR_EOF
  2098. if test 8713 -ne "`wc -c < 'main.c'`"
  2099. then
  2100.     echo shar: error transmitting "'main.c'" '(should have been 8713 characters)'
  2101. fi
  2102. fi # end of overwriting check
  2103. echo shar: extracting "'score.c'" '(5337 characters)'
  2104. if test -f 'score.c'
  2105. then
  2106.     echo shar: will not over-write existing file "'score.c'"
  2107. else
  2108. cat << \SHAR_EOF > 'score.c'
  2109. /*
  2110.  * score.c  --  xrobots v1.0
  2111.  *
  2112.  * flock() is used to stop a race condition within... if you don't 
  2113.  * have a bsd-like flock(), you could probably comment it out.
  2114.  * The race condition (multiple users writing to the score file) is 
  2115.  * probably rare.
  2116.  */
  2117.  
  2118. #include <X11/Intrinsic.h>
  2119. #include <X11/StringDefs.h>
  2120. #include <X11/Shell.h>
  2121. #include <X11/Box.h>
  2122. #include <X11/Command.h>
  2123. #include <X11/Label.h>
  2124. #include <stdio.h>
  2125. #include <sys/file.h>
  2126. #include "score.h"
  2127. #include "game.h"
  2128.  
  2129. /*----------------------------------------------------------------------*/
  2130.  
  2131. typedef struct {
  2132.   char     score[6], 
  2133.     name[26];
  2134. } SCORE;
  2135.  
  2136. static SCORE scores[MAXSCORES];
  2137.  
  2138. void     show_scores(), 
  2139.     new_high_score(), 
  2140.     load_scores(), 
  2141.     write_out_scores();
  2142.  
  2143. static FILE *scorefile = 0;
  2144.  
  2145. /*----------------------------------------------------------------------*/
  2146.  
  2147. void
  2148. check_score(current_score)
  2149.   int current_score;
  2150. {
  2151.  
  2152.   load_scores();
  2153.  
  2154.   if(current_score > atoi(scores[MAXSCORES-1].score)) {
  2155.     new_high_score(current_score);
  2156.     write_out_scores();
  2157.   }
  2158.   if(scorefile) {
  2159.     flock(scorefile->_file, LOCK_UN);
  2160.     fclose(scorefile);
  2161.     show_scores();
  2162.   }
  2163. }
  2164.  
  2165.  
  2166. static void
  2167. load_scores()
  2168. {
  2169.   int i = 0;
  2170.  
  2171.   if( !(scorefile = fopen(SCORE_FILE,"r+")) ) {
  2172.     scorefile = fopen(SCORE_FILE, "w");
  2173.     return;
  2174.   }
  2175.   flock(scorefile->_file, LOCK_EX);
  2176.   while( fgets(scores[i].score,6,scorefile)     /* get score */
  2177.       && fgets(scores[i].name,26,scorefile)     /* get name */
  2178.       && fgetc(scorefile))            /* and newline */
  2179.   {
  2180.     i++;
  2181.     if( i > MAXSCORES ) break;
  2182.   }
  2183. }
  2184.  
  2185.  
  2186. static void
  2187. new_high_score(current_score)
  2188.   int current_score;
  2189. {
  2190.   int i;
  2191.   char textscore[6],
  2192.        name[26];
  2193.  
  2194.   sprintf(textscore,"%5d",current_score);
  2195.   strncpy(name,getenv("USER"),25);
  2196.  
  2197.   for(i=MAXSCORES-2;i>=0;i--)
  2198.     if( current_score < atoi(scores[i].score) ) {
  2199.          /* move new score into i+1 slot */
  2200.       strcpy(scores[i+1].score,textscore);
  2201.       strcpy(scores[i+1].name,name);
  2202.       return;
  2203.     } else {
  2204.       strcpy(scores[i+1].score,scores[i].score);
  2205.       strcpy(scores[i+1].name,scores[i].name);
  2206.     }
  2207.   /* if it got here, there is a new number 1 score */
  2208.   strcpy(scores[0].score,textscore);
  2209.   strcpy(scores[0].name,name);
  2210.  
  2211. }
  2212.  
  2213.  
  2214. static void
  2215. write_out_scores()
  2216. {
  2217.   int i;
  2218.  
  2219.   if( !scorefile )
  2220.     return;
  2221.   rewind(scorefile);
  2222.   for(i=0;i<MAXSCORES;i++)
  2223.     fprintf(scorefile,"%5s%25s\n",scores[i].score,scores[i].name);
  2224. }
  2225.  
  2226.  
  2227. /*----------------------------------------------------------------------*/
  2228.  
  2229.  
  2230. Widget score_popup;
  2231. Widget score_labels[MAXSCORES];
  2232.  
  2233. static Arg arglist_score_title[] = {
  2234.   {  XtNborderWidth, (XtArgVal) 0  },
  2235.   {  XtNresize, (XtArgVal) False  },
  2236.   {  XtNwidth, (XtArgVal) 300   },
  2237.   {  XtNheight, (XtArgVal) 30   },
  2238.   {  XtNlabel, (XtArgVal) "High Scores"  },
  2239.   {  XtNjustify, (XtArgVal) XtJustifyCenter  },
  2240. };
  2241.  
  2242. static Arg arglist_score_label[] = {
  2243.   {  XtNlabel, (XtArgVal) 0  },
  2244.   {  XtNborderWidth, (XtArgVal) 0  },
  2245.   {  XtNresize, (XtArgVal) False  },
  2246.   {  XtNwidth, (XtArgVal) 300   },
  2247.   {  XtNjustify, (XtArgVal) XtJustifyCenter  },
  2248. };
  2249.  
  2250. static Arg arglist_popdown[] = {
  2251. /*  {  XtNborderWidth, (XtArgVal) 2  },*/
  2252.   {  XtNresize, (XtArgVal) False  },
  2253.   {  XtNwidth, (XtArgVal) 300   },
  2254.   {  XtNlabel, (XtArgVal) "Pop Down"  },
  2255.   {  XtNjustify, (XtArgVal) XtJustifyCenter  },
  2256. };
  2257.  
  2258.  
  2259. /*ARGSUSED*/
  2260. static XtCallbackProc 
  2261. popdown_callback(w, closure, call_data)
  2262.   Widget w;
  2263.   caddr_t closure;
  2264.   caddr_t call_data;
  2265. {
  2266.   XtPopdown(score_popup);
  2267. }
  2268.  
  2269.  
  2270. void
  2271. create_high_score_popup(parent)
  2272.   Widget parent;
  2273. {
  2274.   int i;
  2275.   Widget score_box, popdown;
  2276.  
  2277.   score_popup = XtCreatePopupShell(
  2278.                                    "score_popup",
  2279.                                    transientShellWidgetClass,
  2280.                                    parent, 0,0);
  2281.  
  2282.   score_box = XtCreateManagedWidget(
  2283.                                     "score_box",
  2284.                                     boxWidgetClass,
  2285.                                     score_popup,
  2286.                                     0,0);
  2287.  
  2288.   (void)XtCreateManagedWidget(
  2289.                                     "score_title",
  2290.                                     labelWidgetClass,
  2291.                                     score_box,
  2292.                                     arglist_score_title,
  2293.                                     XtNumber(arglist_score_title));
  2294.  
  2295.   for(i=0;i<MAXSCORES;i++) {
  2296.     score_labels[i] = XtCreateManagedWidget(
  2297.                                     "alabel",
  2298.                                     labelWidgetClass,
  2299.                                     score_box,
  2300.                                     arglist_score_label,
  2301.                                     XtNumber(arglist_score_label));
  2302.   }
  2303.  
  2304.   popdown = XtCreateManagedWidget(
  2305.                                     "popdown",
  2306.                                     commandWidgetClass,
  2307.                                     score_box,
  2308.                                     arglist_popdown,
  2309.                                     XtNumber(arglist_popdown));
  2310.   XtAddCallback(popdown,XtNcallback,popdown_callback,0);
  2311. }
  2312.  
  2313.  
  2314.  
  2315. void
  2316. show_scores()
  2317. {
  2318.   int i;
  2319.   char tmp_str[31];
  2320.   Arg tmp_arg;
  2321.  
  2322.   for(i = 0;i<MAXSCORES;i++) {
  2323.     sprintf(tmp_str,"%5s  %25s", scores[i].score, scores[i].name);
  2324.     XtSetArg(tmp_arg,XtNlabel,tmp_str);
  2325.     XtSetValues(score_labels[i],&tmp_arg,1);
  2326.   }
  2327.   XtPopup(score_popup, XtGrabNone);
  2328. }
  2329.  
  2330.  
  2331. /*----------------------------------------------------------------------*/
  2332.  
  2333. SHAR_EOF
  2334. if test 5337 -ne "`wc -c < 'score.c'`"
  2335. then
  2336.     echo shar: error transmitting "'score.c'" '(should have been 5337 characters)'
  2337. fi
  2338. fi # end of overwriting check
  2339. echo shar: extracting "'score.h'" '(225 characters)'
  2340. if test -f 'score.h'
  2341. then
  2342.     echo shar: will not over-write existing file "'score.h'"
  2343. else
  2344. cat << \SHAR_EOF > 'score.h'
  2345. /*
  2346.  * score.h  --  xrobots v1.0
  2347.  */
  2348.  
  2349. #ifndef SCORE_FILE
  2350. #  define SCORE_FILE "/usr/games/lib/xrobots_scores"
  2351. #endif
  2352.  
  2353. #ifndef MAXSCORES
  2354. #  define MAXSCORES 20
  2355. #endif
  2356.  
  2357. extern void     check_score(), 
  2358.         create_high_score_popup();
  2359.  
  2360. SHAR_EOF
  2361. if test 225 -ne "`wc -c < 'score.h'`"
  2362. then
  2363.     echo shar: error transmitting "'score.h'" '(should have been 225 characters)'
  2364. fi
  2365. fi # end of overwriting check
  2366. echo shar: extracting "'xrobots.man'" '(4066 characters)'
  2367. if test -f 'xrobots.man'
  2368. then
  2369.     echo shar: will not over-write existing file "'xrobots.man'"
  2370. else
  2371. cat << \SHAR_EOF > 'xrobots.man'
  2372. .\" Man page for xrobots.
  2373. .TH XROBOTS 6 "11 May 1989"
  2374. .SH NAME
  2375. xrobots \- fight off villainous robots (X Windows)
  2376. .SH SYNOPSIS
  2377. .B /usr/games/xrobots 
  2378. .SH DESCRIPTION
  2379. .LP
  2380. As in robots(6), xrobots puts you into a world of evil robots (but in
  2381. an X window, of course).
  2382. It's your intellect against the robots, who have numbers on their side.
  2383. Fortunately for you, these robots have a bad habit of crashing into 
  2384. each other, destroying themselves and putting you in a better position
  2385. to survive.
  2386. .LP
  2387. You have a the following abilities: 
  2388. .LP
  2389. .RS
  2390. You can move one square at a time (but so can the robots).  
  2391. These directions are indicated by diamonds near your man.
  2392. Clicking the left mouse button selects the direction.
  2393. .LP
  2394. You can wait for robots to reach you.  Do this by clicking on
  2395. the button labeled "Wait" below the main playfield or by 
  2396. pressing 'w' while the mouse pointer is within the playfield.
  2397. .LP
  2398. You can use your teleportation device.  This defensive weapon
  2399. is not without risk.  This can be invoked by clicking on 
  2400. "Teleport" or by pressing 't'.
  2401. .LP
  2402. You have a "sonic screwdriver" which wipes out any robots 
  2403. within close proximity.  This offensive weapon recharges once for 
  2404. each level.  This can be invoked by the "Sonic Screwdiver" button
  2405. or by pressing 's'.
  2406. .RE
  2407. .LP
  2408. .SH RESOURCES
  2409. .LP
  2410. If you don't like 's' for the sonic screwdriver and 't' for teleport
  2411. you can change this.  xrobots is programmed using the X Toolkit and 
  2412. takes advantage of the toolkit's resources and translation schemes.  
  2413. For example, if you don't want all the spiffy graphics, place
  2414. the following line in your .Xdefaults file.
  2415. .LP
  2416. .RS
  2417. xrobots.spiffy: false
  2418. .RE
  2419. .LP
  2420. The default for this resource is true.
  2421. .LP
  2422. Additionally, all the key bindings can be changed.  Here's a sample
  2423. set of translation bindings:
  2424. .LP
  2425. .RS
  2426. xrobots*Translations:   #augment     \\n\\ 
  2427. .RS
  2428. .nf
  2429. <Btn1Up>:    move()             \\n\\ 
  2430. <Key>u:      move(right, up)    \\n\\ 
  2431. <Key>l:      move(right)        \\n\\ 
  2432. <Key>n:      move(right, down)  \\n\\ 
  2433. <Key>y:      move(left, up)     \\n\\ 
  2434. <Key>h:      move(left)         \\n\\ 
  2435. <Key>b:      move(left, down)   \\n\\ 
  2436. <Key>k:      move(up)           \\n\\ 
  2437. <Key>j:      move(down)         \\n\\ 
  2438. <Key>.:      move(nowhere)      \\n\\ 
  2439. <Key>\\\\ :    move(nowhere)      \\n\\ 
  2440. <Btn2Up>:    go_here()          \\n\\ 
  2441. <Btn3Up>:    wait()             \\n\\ 
  2442. <Key>s:      sonic()            \\n\\ 
  2443. <Key>t:      teleport()         \\n\\ 
  2444. <Key>w:      wait()             \\n\\ 
  2445. <Key>z:      new_game()         \\n\\ 
  2446. :<Key>Q:      quit()
  2447. .fi
  2448. .RE
  2449. .RE
  2450. .RE
  2451. .LP
  2452. Of course, these defaults should copied into your .Xdefaults file to
  2453. take effect.  You studs out there might even use xrdb(1).
  2454. .LP
  2455. .SH ACTIONS
  2456. .LP
  2457. Here's what each action is and what it does:
  2458. .RS
  2459. .LP
  2460. The move() action with no parameters uses the relative position of the 
  2461. mouse pointer to determine the direction in which to go.  Otherwise,
  2462. a combination of "left", "right", "up", "down", and "nowhere" will 
  2463. direct the direction.  If "nowhere" is used, the player's icon will
  2464. remain still while the robots take their turn.
  2465. .LP
  2466. The go_here() action directs the player's icon to the location where the
  2467. mouse button was released.  Of course, the robots will chase you, and
  2468. if doom is impending, go_here() will stop.
  2469. .LP 
  2470. The wait() action causes the robots to move until they are breathing
  2471. right down your neck.
  2472. .LP  
  2473. The sonic() action invokes the sonic screwdriver.
  2474. .LP
  2475. The teleport() action invokes the teleportation device.
  2476. .LP
  2477. The new_game() and quit() actions do what you would expect them to. 
  2478. .LP
  2479. .SH SCORING
  2480. .LP
  2481. Each robot that is wasted is worth ten points.  Additionally, 
  2482. bonuses are awarded for each teleportation, and for not using the 
  2483. sonic screwdriver.  The name for the high score list comes from
  2484. the USER environment variable.
  2485. .LP
  2486. .SH FILES
  2487. .LP
  2488. /usr/games/lib/xrobots_scores \-\- the score file
  2489. .LP
  2490. .SH AUTHOR
  2491. .LP
  2492. There are many versions of robots floating around.  So many that it
  2493. would be difficult to say who the original author is.  This version was
  2494. written from scratch by Brian Warkentine.
  2495.  
  2496. SHAR_EOF
  2497. if test 4066 -ne "`wc -c < 'xrobots.man'`"
  2498. then
  2499.     echo shar: error transmitting "'xrobots.man'" '(should have been 4066 characters)'
  2500. fi
  2501. fi # end of overwriting check
  2502. #    End of shell archive
  2503. exit 0
  2504.